package com.easyj.base.storage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.easyj.base.common.ajax.Result;
import com.easyj.base.common.storage.FileInfo;
import com.easyj.base.controller.BaseController;
import com.easyj.base.exception.FileStoreException;
import com.easyj.base.storage.service.StorageService;



/**
* 上传文件
*
 */
@RestController
@RequestMapping(value = "/upload")
public class UploadController extends BaseController{
	
	@Autowired
	private  StorageService storageService;
    
	/**
	 * 配合element upload 控件
	 * 直接  throw error
	 * @param file
	 * @return
	 * @throws FileStoreException
	 */
	@RequestMapping(value = "saveAppendFile", method = RequestMethod.POST)
	public Result saveAppendFile(@RequestParam MultipartFile file) throws FileStoreException{
		
		FileInfo path=storageService.storeAppendFile(file);
		return Result.Success(path);
	}
	
	/**
	 * 配合element upload 控件
	 * 直接  throw error
	 * @param file
	 * @return
	 * @throws FileStoreException
	 */
	@RequestMapping(value = "saveImageFile", method = RequestMethod.POST)
	public Result saveImageFile(@RequestParam MultipartFile file) throws FileStoreException{
		
		FileInfo path=storageService.storeImageFile(file);
		return Result.Success(path);
	}
}
